package cc.yaomm.service.basic.controller.business.user;

import cc.yaomm.common.basic.domain.Response;
import cc.yaomm.service.basic.controller.business.BaseAdminController;
import cc.yaomm.service.basic.controller.business.user.biz.PermissionBiz;
import cc.yaomm.service.basic.controller.business.user.biz.ResourceBiz;
import cc.yaomm.service.basic.controller.business.user.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Set;

/**
 * Created by XQL on 2021/6/9.
 */
@RestController
@RequestMapping("${apps.biz}/permission")
@Api(tags = "权限接口")
@Slf4j
@Validated
public class PermissionController extends BaseAdminController {

    @Autowired
    private PermissionBiz permissionBiz;

    @PostMapping("list")
    @ApiOperation(value = "权限列表", notes = "权限列表")
    public Response<List<PermissionResultVO>> list(@RequestBody PermissionParamVO paramVO) {
        return Response.success(permissionBiz.findTree(paramVO));
    }

    @PostMapping("lock")
    @ApiOperation(value = "锁定/解锁权限", notes = "锁定/解锁权限")
    @Validated(PermissionParamVO.Lock.class)
    public Response<Void> lock(@RequestBody @Valid PermissionParamVO paramVO) {
        permissionBiz.lock(paramVO);
        return Response.success();
    }

    @PostMapping({"create", "edit"})
    @ApiOperation(value = "新增/编辑权限", notes = "新增/编辑权限")
    @Validated(PermissionParamVO.Edit.class)
    public Response<Void> create(@RequestBody @Valid PermissionParamVO paramVO) {
        permissionBiz.save(paramVO);
        return Response.success();
    }

    @GetMapping("detail")
    @ApiOperation(value = "权限详情", notes = "权限详情")
    public Response<PermissionDetailResultVO> detail(@RequestParam("id") Long id) {
        return Response.success(permissionBiz.detail(id));
    }
}
